$(document).ready(function(){
    init();
});

function update(){
    var name = $("input[name='name']").val();
    var id = $("input[name='id']").val();

    $.ajax({
        url: "/fenlei/update",
        type: 'GET',
        data: {
            "name": name,
            "id": id
        },
        dataType: "JSON",
        async: false,
        success: function (res) {
            if(res.code === "200") {
                window.location.href = "/fenleilist";
            }else {
                alert(res.msg)
            }
        },
        error: function (e){
            alert('发生错误')
        }

    })

}

function init(){

    var path = location.href;
    var id = path.substring(path.lastIndexOf("/")+1)

    $.ajax({
        url: "/fenlei/"+ id,
        type: 'GET',
        data: {
        },
        dataType: "JSON",
        async: false,
        success: function (res) {
            if(res.code === "200") {
                var data = res.data;

                $("#name").val(data.name);
                $("#id").val(data.id);
            }else {
                alert(res.msg)
            }
        },
        error: function (e){
            alert('发生错误')
        }

    })

}
